import java.net.*;
import java.io.*;




public class Reverse {

	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws Exception {
		if(args.length != 1){
			System.err.println("다음형식으로 입력하세요.");
			System.err.println("java Reverse \"string\"");
			System.exit(1); //제로 이외의 상태 코드는 이상종료(ABEND)를 나타냅니다.  			
		}
		
		String stringToReverse= URLEncoder.encode(args[0]);
		
		URL url = new URL("http://java.sun.com/cgi-bin/backwards");
		URLConnection connection = url.openConnection();
		connection.setDoOutput(true);
		PrintWriter out = new PrintWriter(connection.getOutputStream());
		out.println("string=" + stringToReverse);
		out.close();
		BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
		String line=null;
		while((line=in.readLine()) != null)
			System.out.println(line);
			in.close();

	}

}

